home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8344 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: dereferencing pointer to incomplete type
  5. Date: 3 Mar 1996 12:38:59 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4hc3t3$geh@sparcserver.lrz-muenchen.de>
  9. References: <1996Mar3.040741.27234@dcs.warwick.ac.uk>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. D.C.Molero@dcs.warwick.ac.uk (Daniel Castillo Molero) writes:
  13.  
  14.  
  15. >Hi everybody.
  16. >I wonder if anybody can help me to debug the short code below.
  17. >It is supposed to calculate the area of a polygon, but when I compile
  18. >it with  gcc program.c, it gives me the following errors,
  19.  
  20. >program.c: In function `calc_area':
  21. >program.c:22: warning: assignment from incompatible pointer type
  22. >program.c:24: dereferencing pointer to incomplete type
  23. >program.c:24: dereferencing pointer to incomplete type
  24. >program.c:26: warning: assignment from incompatible pointer type
  25.  
  26. >which I don't understand at all.
  27.  
  28. >I would appreciate very much any sort of help.
  29.  
  30. >------------------
  31.  
  32. >struct polygon
  33. >{
  34. >  int tried;
  35. >  double x, y;
  36. >  int dir, numtimes, conv;
  37. >  struct polyg *next;
  38. ^^^^^^^^^^^^^^^ What is a "struct ployg"? A compiler cannot make the
  39. "obvious" connection between "struct polygon" and "struct polyg", so
  40. "next" is a pointer to an incolmplete type, i.e. to a struct that 
  41. will be defined somewhere else in your program.
  42. >};
  43.  
  44. [unrelated code edited]
  45.  
  46. >void calc_area(struct polygon* polyg, double* area) {
  47.  
  48. Calling the parameter polyg will _not_ help to introduce a connection
  49. between the variable "polyg" and the incomplete type "struct polyg".
  50.  
  51. >struct polygon* p;
  52. >double result;
  53. >p = polyg->next;
  54.  
  55. Now you try to assign a pointer to an incomplete type to a pointer to
  56. a "struct polygon".
  57.  
  58. Hint: Sometimes it is useful to check your spelling if you get a 
  59. "strange" diagnostic.
  60.  
  61. Kurt
  62. --
  63. | Kurt Watzka                             Phone : +49-89-2180-6254
  64. | watzka@stat.uni-muenchen.de
  65. | ua302aa@sunmail.lrz-muenchen.de
  66.